# -*- coding:utf-8 -*-
from datetime import datetime

from django.db import models
from django.contrib.auth.models import AbstractUser


class UserProfile(AbstractUser):
    nick_name = models.CharField(u'昵称', max_length=50, default=u'')
    gender = models.CharField(u'性别', choices=(
        ('male', u'男'), ('female', u'女')), default='male', max_length=6)
    birday = models.DateField(u'生日', null=True, blank=True)
    mobile = models.CharField(u'手机', max_length=11, null=True, blank=True)
    address = models.CharField(u'地址', max_length=100, null=True, blank=True)
    image = models.ImageField(u'头像', upload_to='image/%Y/%m', default='image/default.jpg', max_length=100)

    class Meta(AbstractUser.Meta):
        verbose_name = u'用户信息'
        verbose_name_plural = verbose_name

    def __unicode__(self):
        return self.username


class EmailVerifyRecord(models.Model):
    code = models.CharField(u'验证码', max_length=50)
    email = models.EmailField(u'邮箱', max_length=32)
    send_type = models.CharField(u'验证码类型', choices=(('register', u'注册'), ('forget', u'找回密码')), max_length=10)
    send_time = models.DateTimeField(u'发送时间', default=datetime.now)

    class Meta:
        verbose_name = u'邮箱验证码'
        verbose_name_plural = verbose_name

    def __unicode__(self):
        return '{0}({1})'.format(self.code, self.email)


class Banner(models.Model):
    title = models.CharField(u'标题', max_length=100)
    image = models.ImageField(u'轮播图', upload_to='banner/%Y/%m', blank=True)
    url = models.URLField(u'访问地址', max_length=200)
    index = models.IntegerField(u'顺序', default=100)
    add_time = models.DateTimeField(u'添加时间', default=datetime.now)

    class Meta:
        verbose_name = u'轮播图'
        verbose_name_plural = verbose_name

    def __unicode__(self):
        return self.title


class Advertisement(models.Model):
    title = models.CharField(u'标题', max_length=100)
    image = models.ImageField(u'图片', upload_to='advertisement/%Y/%m', blank=True)
    url = models.URLField(u'访问地址', max_length=200)
    priority = models.IntegerField(u'优先级', default=100)
    add_time = models.DateTimeField(u'添加时间', default=datetime.now)

    class Meta:
        verbose_name = u'广告'
        verbose_name_plural = verbose_name

    def __unicode__(self):
        return self.title